from pathlib import Path
import yaml


# 读取 YAML 文件
def read_yaml(yaml_file_name):
    try:
        with open(yaml_file_name, 'r', encoding='utf-8') as f:
            value = yaml.safe_load(f)
        return value
    except Exception as e:
        raise e


def get_cases(yaml_file_path):
    """
    data目录下对应yaml文件读取测试用例
    :param yaml_file_path:
    :return: test_case
    """
    test_case = read_yaml(Path(__file__).parents[1] / f"{yaml_file_path}")['test_cases']
    return test_case


if __name__ == '__main__':
    PROJECT_ROOT = Path(__file__).parent.parent
    yaml_path = PROJECT_ROOT / "data/wechat/draft/add_draft.yaml"
    print(
        read_yaml(yaml_path)[
            "test_cases"])

    test_cases = get_cases("data/httpbin/HTTPMethods/GET.yaml")
    print(test_cases)
